const Koa = require('koa');
const KoaBody = require('koa-body');
const KoaRouter = require('koa-router');

const app = new Koa();
app.use(KoaBody({ multipart: true }));

let router = new KoaRouter();

var i = 20000;
router.all('/test', async (ctx,next) =>{
    ctx.response.body = 'success'
});

const errorHandler = async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    console.log(err);
    ctx.response.status = err.statusCode || err.status || 500;
    ctx.response.body = {
      message: err.message
    };
  }
};

app
  .use(errorHandler)
  .use(router.routes())
  .use(router.allowedMethods());

app.on('error', function (err) {
  console.log(err);
});

app.listen(9016,()=>{
  console.log(`server start at port : 9016`);
});




// let bluebird = require("bluebird");
// let redis = require('redis');
// let redisConfig = {
//   "port": 6379,
//   "host": "127.0.0.1",
//   "password":"",
//   "db": 1,
//   "prefix": "__node:"
// }
// let redisClient = redis.createClient(redisConfig);

// const __subscribe = async () =>{
//     redisClient.subscribe('timer_close',function(e){
//       //接收消息进行关闭应用
//       console.log(e);
//   });
// }

// //redis挂了重新订阅
// redisClient.on("error", function (err) {
//   __subscribe();
// });

// redisClient.on('message',function(err,response){
//   console.log("处理订阅"+response);
// });

// __subscribe();


const moment = require('moment');
const schedule = require('node-schedule');
console.log( moment().format('YYYY-MM-DD HH:mm:ss')+' 间隔执行');

schedule.scheduleJob('*/63 * * * * *',async ()=>{
  console.log( moment().format('YYYY-MM-DD HH:mm:ss')+' 间隔执行');
})